/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tesam.gedeon.controller;

import com.tesam.gedeon.entity.Country;
import com.tesam.gedeon.entity.Department;
import com.tesam.gedeon.entity.District;
import com.tesam.gedeon.entity.Province;
import com.tesam.gedeon.service.DistrictService;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author Sistema
 */
@Controller
public class DistrictController {
    
    @Autowired
    SystemUserController system ;
    @Autowired
    DistrictService districtService ;
    Country country = new Country();
    Department department = new Department();
    Province province = new Province();
    
    @RequestMapping(value = "/district/byprovinceanddepartmentandcountry")
    public ModelAndView getDistrictByProvinceAndDepartmentAndCountry(@ModelAttribute("District") District district , 
                                    HttpServletRequest request){
        ModelAndView mv = new ModelAndView("/district/byprovinceanddepartmentandcountry");
          
        country.setCode(request.getParameter("codeCountry").toString());
        department.setCode(request.getParameter("codeDepartment").toString());
        province.setCode(request.getParameter("codeProvince").toString());
        district.setCountry(country);
        district.setProvince(province);
        district.setDepartment(department);
        
        mv.addObject("district", districtService.getDistrictByProvinceAndDepartmentAndCountry(district));
        
        return mv;
    }
    
}
